//
//  DemoTableViewCell.m
//  DemoTableView
//
//  Created by wenchao on 15/12/26.
//  Copyright © 2015年 wenchao. All rights reserved.
//

#import "DemoTableViewCell.h"

@implementation DemoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
        self.textLabel.numberOfLines = 0;
    }
    
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (NSString *)cellIdentifier {
    return NSStringFromClass([DemoTableViewCell class]);
}

+ (CGFloat)calulateHeightWithtTitle:(NSString*)title {
    
    CGFloat height =10;
    
    CGSize labelSize = [title boundingRectWithSize:CGSizeMake(300, 2000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.]} context:nil].size;
    
    height = height + labelSize.height;
    
    return height;
    
}

-(CGFloat)calulateHeightWithtTitle:(NSString*)title desrip:(NSString*)descrip {
    //这里非常重要
    CGFloat preMaxWaith =[UIScreen mainScreen].bounds.size.width-30;
    [self.textLabel setPreferredMaxLayoutWidth:preMaxWaith];
    //    [self.titleLabel setText:title];
    //这也很重要
    [self.textLabel layoutIfNeeded];
    [self.textLabel setText:title];
    [self.contentView layoutIfNeeded];
    CGSize size = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    //加1是关键
    return size.height+1.0f;
}

@end
